package cn.dengta.webapp.trade.form;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;

import cn.dengta.common.util.Formats;
import cn.dengta.webapp.trade.model.PaymentMethod;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

@Getter
@Setter
public class PayerMaxReqForm implements Serializable {

	/** 账号id */
	private Long accountId;
	/** 订单编号 */
	private String orderNo;
	/** 国家码 */
	private String country;
	/** 提现币种 */
	private String currency;
	/** 交易方式 */
	private PaymentMethod paymentMethod;
	/** 金额 */
	private String amount;
	/** 收款方名 */
	private String firstName;
	/** 收款方姓 */
	private String lastName;
	/** 收款方中间名，多段中间名时，使用空格进行分隔 */
	private String middleName;
	/** 账号：银行卡 或者 钱包 */
	private String accountNo;
	/** 银行机构编码 */
	private String targetOrg;
	private String ifscCode;
	/** 手机号 */
	private String phone;
	/** 邮箱 */
	private String email;
	/** 地址 */
	private String address;

	private String accType;

	private String zipCode;
	private String addrCity;
	private String addrState;
	/**
	 * 哥伦比亚 收款方个人身份证明类型 --大写字母，取值范围见下, NIT：纳税人识别号, CC：公民卡, PASS：护照，CE：外国人身份证
	 */
	private String docType;
	private String docId;
	private String bankBranch;
	private String checkDigit;



	public String getFullName() {
		return buildFullName(this.country, this.firstName, this.middleName, this.lastName);
	}

	public static String buildFullName(String country, String firstName, String middleName, String lastName) {
		// 菲律宾用逗号
		if (StringUtils.isNotEmpty(firstName) && StringUtils.isNotEmpty(lastName)) {
			if ("PH".equals(country)) {
				if (StringUtils.isNotEmpty(middleName)) {
					return lastName + "," + firstName + "," + middleName;
				}
				return lastName + "," + firstName;
			}
			return firstName + " " + lastName;
		}
		return "";
	}

	public void buildAmount(BigDecimal amount) {
		this.amount = buildAmount(this.country, amount, RoundingMode.DOWN);
	}

	public static String buildAmount(String country, BigDecimal amount, RoundingMode mode) {
		String amo;
		if (isRounding(country)) {
			BigDecimal bigDecimal = amount.setScale(0, mode);
			amo = String.valueOf(bigDecimal.longValue());
		} else {
			BigDecimal bigDecimal = amount.setScale(2, mode);
			amo = bigDecimal.toString();
		}
		return amo;
	}

	public static boolean isRounding(String country) {
		return "ID".equals(country) || "VN".equals(country) || "PH".equals(country) || "TH".equals(country);
	}

	public static String buildAmountFormat(String country, BigDecimal amount, RoundingMode mode) {
		if (isRounding(country)) {
			BigDecimal bigDecimal = amount.setScale(0, mode);
			return Formats.formatNumber_INT(bigDecimal);
		}
		BigDecimal bigDecimal = amount.setScale(2, mode);
		return Formats.formatNumber_M(bigDecimal);
	}

	public void setFirstName(String firstName) {
		if (firstName != null) {
			this.firstName = firstName.trim();
		}
	}

	public void setLastName(String lastName) {
		if (lastName != null) {
			this.lastName = lastName;
		}
	}

	public void setMiddleName(String middleName) {
		if (middleName != null) {
			this.middleName = middleName.trim();
		}
	}

}
